package com.hy.controller;

import com.hy.common.Result;
import com.hy.entity.Points;
import com.hy.service.PointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/points")
public class PointsController {

    @Autowired
    private PointsService pointsService;

    @GetMapping
    public Result<List<Points>> getAllPoints() {
        return Result.success(pointsService.list());
    }

    @GetMapping("/{id}")
    public Result<Points> getPoints(@PathVariable Long id) {
        return Result.success(pointsService.getById(id));
    }

    /**
     * 用户打卡API
     */
    @PostMapping("/userAddRecords")
    public Result<Boolean> userAddRecords() {
        return pointsService.userAddRecords();
    }

    @PostMapping
    public Result<Boolean> addPoints(@RequestBody Points points) {
        return Result.success(pointsService.save(points));
    }

    @PutMapping("/{id}")
    public Result<Boolean> updatePoints(@PathVariable Long id, @RequestBody Points points) {
        points.setId(id);
        return Result.success(pointsService.updateById(points));
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deletePoints(@PathVariable Long id) {
        return Result.success(pointsService.removeById(id));
    }
} 